package com.example.zhaohang.mynewtimeselect;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import org.feezu.liuli.timeselector.TimeSelector;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeSelectOne extends AppCompatActivity {

    private TimeSelector mTimeSelector;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time_select_one);


        mTimeSelector = new TimeSelector(TimeSelectOne.this, new TimeSelector.ResultHandler() {
            @Override
            public void handle(String time) {
                //                Toast.makeText(TimeSelectOne.this, time, Toast.LENGTH_SHORT).show();
                ToastMake.ShowText(TimeSelectOne.this, time);

            }
        }, "2015-01-01 00:00", "2018-12-31 23:59:59");

        //限制选择小时时段
        //        TimeSelector timeSelector = new TimeSelector(TimeSelectOne.this, new TimeSelector.ResultHandler() {
        //            @Override
        //            public void handle(String time) {
        //                Toast.makeText(TimeSelectOne.this, time, Toast.LENGTH_SHORT).show();
        //            }
        //        }, "2015-01-01 00:00", "2018-12-31 23:59:59", "9:00", "17:00");

        mTimeSelector.setIsLoop(false);//设置不循环,true循环

        mTimeSelector.setMode(TimeSelector.MODE.YMDHM);//显示 年月日时分（默认）
        //        timeSelector.setMode(TimeSelector.MODE.YMD);//只显示 年月日

        mTimeSelector.show();
    }

    //当地时间
    public void lacotime(View view) {

        //获取当前时间 (import  java.text.SimpleDateFormat;)
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date curDate = new Date(System.currentTimeMillis());
        String date = formatter.format(curDate);


        ToastMake.ShowText(TimeSelectOne.this, date);
    }


    //精确到秒的时间选择器
    public void miaotime(View view) {
        mTimeSelector.setIsLoop(false);//设置不循环,true循环

        mTimeSelector.setMode(TimeSelector.MODE.YMDHM);//显示 年月日时分（默认）
        //        mTimeSelector.setMode(TimeSelector.MODE.YMD);//只显示 年月日

        mTimeSelector.show();
    }

    public void nianritime(View view) {

        mTimeSelector.setIsLoop(false);//设置不循环,true循环

        //        mTimeSelector.setMode(TimeSelector.MODE.YMDHM);//显示 年月日时分（默认）
        mTimeSelector.setMode(TimeSelector.MODE.YMD);//只显示 年月日

        mTimeSelector.show();
    }
}
